package com.chuangfeng.building.ms.login.dao.impl;

import org.hibernate.Criteria;
import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Repository;

import com.chuangfeng.building.common.CoreDaoImpl;
import com.chuangfeng.building.entity.TAdminInfo;
import com.chuangfeng.building.ms.login.dao.AdminDao;
import com.chuangfeng.framework.core.exception.PersistenceException;

@Repository
public class AdminDaoImpl extends CoreDaoImpl<TAdminInfo> implements AdminDao {

	public TAdminInfo checkAdmin(String userName, String password) {
		try {
			Criteria criteriaAccout = this.getSession().createCriteria(TAdminInfo.class);
			criteriaAccout.add(Restrictions.and(Restrictions.eq("userName", userName), Restrictions.eq("password", password)));
			TAdminInfo adminInfo = (TAdminInfo) criteriaAccout.uniqueResult();
			return adminInfo;
		} catch (Exception e) {
			logger.error(e.getMessage());
			throw new PersistenceException(e.getMessage());
		}
	}

}
